from rest_framework import filters
from rest_framework.exceptions import ValidationError

from apps.location.models import Room


def booking_filter_queryset(request, queryset):
    query = queryset
    params = request.query_params

    if 'room' in params:
        query = query.filter(room=params['room'])

    if 'status' in params:
        query = query.filter(status=params['status'])

    if 'location' in params:
        rooms = Room.objects.filter(location__id=params['location']).values_list('id')
        query = query.filter(room__in=rooms)

    return query